package com.biz.hunter.dao;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Repository;

import com.biz.hunter.db.entity.WxAppUser;
import com.biz.hunter.dbutil.BaseDAO;

@Repository
public class WxAppUserDAO {
	Logger logger = LoggerFactory.getLogger(WxAppUserDAO.class);
	private static final String SQL_GET = "select * from wxapp_user where openid = ?";
	private static final String SQL_BIND_PHONE="insert into wxapp_user(mobile,openid) values(?,?)";
	
	public WxAppUser getByOpenId(String openid) {
		return BaseDAO.queryForObject(WxAppUser.class, SQL_GET, openid);
	}

	public int savecode(String phone,String openid){
		int result=BaseDAO.execute(SQL_BIND_PHONE, phone,openid);
	    return result;
	}

	public static final String UPDATE_MOBILE = "update wxapp_user set mobile = ? and purePhoneNumber = ? where unionid = ?";
	public int updateMobile(String mobile,String phone,String unionid) {
		return BaseDAO.execute(UPDATE_MOBILE,mobile,phone,unionid);
	}

	public static final String GET_UNIONID = "select * from wxapp_user where unionid = ?";
	public WxAppUser getByUnionid(String unionid) {
		return BaseDAO.queryForObject(WxAppUser.class, GET_UNIONID, unionid);
	}


}
